<!-- 
  
## 红灯 3 秒亮一次，绿灯 1 秒亮一次，黄灯 2 秒亮一次；如何使用 Promise 让三个灯不断交替重复亮灯？

```js
 可能用到的函数
 --> 
<style>
</style>
<button id="red">红灯</button>
<button id="yellow">黄灯</button>
<button id="green">绿灯</button>
<script>
const r= document.getElementById('red')
const g=document.getElementById('green')
const y= document.getElementById('yellow')
function delay(ms) {
  return new Promise(function (resolve) {
    setTimeout(()=>{
     resolve()
    },ms)
  })
}
function red(){
  // console.log('红灯')
 r.style.backgroundColor='red'
 y.style.backgroundColor='white'
 g.style.backgroundColor='white'
  return delay(3000)
 
}

function yellow(){
  // console.log('黄灯')
 r.style.backgroundColor='white'
 g.style.backgroundColor='white'
 y.style.backgroundColor='yellow'
  return delay(2000)
}
function green(){
  y.style.backgroundColor='white'
 r.style.backgroundColor='white'
  g.style.backgroundColor='green'
  // console.log('绿灯')
  return delay(1000)
}
async function light(){
  while(true){
    await red()
    await yellow()
    await green()
  }
}

light()




</script>


